<template>
	<view class="publicize-page">
		<u-swiper :list="swiperList" height="300rpx" radius="0" indicatorStyle="right: 20px" circular :autoplay="swiperAutoplay" @change="swiperChange">
			<view slot="indicator" class="indicator-num">
				<view class="left">
					<text>{{ currentNum + 1 }}</text>
				</view>
				<view class="right">
					<text>{{ swiperList.length }}</text>
				</view>
			</view>
		</u-swiper>
		
		<view class="container">
			<view class="tab-box">
				<view class="tab-item" :class="{'active': tabCurrent === 0}" @click="tabChange(0)">政策法规 <text class="zw">སྲིད་ཇུས་ཁྲིམས་སྲོལ།</text></view>
				<view class="tab-item" :class="{'active': tabCurrent === 1}" @click="tabChange(1)">今日辟谣 <text class="zw">དཀྲོག་གཏམ་ཐེར་འདོན།</text></view>
			</view>
			<view class="list-box">
				<view class="item" v-for="(item, index) in this_data_list" :key="index" @click="goDetail(item.id)">
					<view class="top">
						<view class="info">
							<image class="image" :src="item.title_img" mode="aspectFill"></image>
							<view class="name">{{item.title}}</view>
						</view>
						<view class="time">{{item.add_time}}</view>
					</view>
					<view class="bottom">{{item.jianjie}}</view>
				</view>
			</view>
		</view>
		
		<view class="tabbar-placeholder"></view>
	</view>
</template>

<script>
	const util = require('../../common/util.js');
	const data = require('../../common/data.js');
	export default {
		data() {
			return {
				currentNum: 0,
				swiperList: [],
				swiperAutoplay: true,
				tabCurrent: 0,
				this_data_list:[]
			}
		},
		onShow() {
			// #ifdef MP-WEIXIN
			if (typeof this.$mp.page.getTabBar === 'function' && this.$mp.page.getTabBar()) {
				this.$mp.page.getTabBar().setData({
					selected: 1
				})
			}
			// #endif
			
			this.loadData();
		},
		methods: {
			loadData: function() {
				let that = this;
				var requsetData = {};
				requsetData.select_index = that.tabCurrent+1;
				util.requestPost(
					'/Index/zhengceList',
					requsetData,
					function(res) {
						that.swiperList = res.data.this_ad_list;
						that.this_data_list = res.data.data_list;
					},
					'',
					{ isShowLoading: false }
				);
			},
			swiperChange(e) {
				this.currentNum = e.current
				if ((e.current + 1) === this.swiperList.length) {
					this.swiperAutoplay = false
				}
			},
			tabChange (index) {
				this.tabCurrent = index
				this.loadData()
			},
			goDetail (id) {
				uni.navigateTo({
					url: '/pages/publicize/detail?id='+id
				})
			}
		}
	}
</script>

<style lang="scss">
.publicize-page {
	min-height: 100%;
	background-color: $bg-color;
	.container {
		padding: 32rpx 24rpx;
		.tab-box {
			padding: 16rpx 22rpx;
			border-radius: 100rpx;
			border: 1rpx solid #eeeeee;
			background-color: #f2f2f2;
			display: flex;
			.tab-item {
				flex: 1;
				height: 84rpx;
				font-size: 30rpx;
				text-align: center;
				line-height: 84rpx;
				.zw {
					margin-left: 6rpx;
					font-size: 26rpx;
				}
				&.active {
					color: #fff;
					border-radius: 84rpx;
					background-color: $primary-color;
				}
			}
		}
		.list-box {
			margin-top: 28rpx;
			.item {
				padding: 14rpx;
				border-radius: 30rpx;
				background-color: #fff;
				&:not(:last-child) {
					margin-bottom: 22rpx;
				}
				.top {
					padding: 14rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.info {
						flex: 1;
						display: flex;
						align-items: center;
						.image {
							width: 80rpx;
							height: 80rpx;
							margin-right: 16rpx;
						}
						.name {
							color: #202020;
							font-size: 28rpx;
						}
					}
					.time {
						margin-right: 20rpx;
						color: #666;
						font-size: 24rpx;
					}
				}
				.bottom {
					border-top: 1rpx solid #f0f0f0;
					padding: 14rpx;
					color: #424242;
					font-size: 28rpx;
				}
			}
		}
	}
}
</style>
